package com.yuebao.init;

import cn.hutool.json.JSONUtil;



import com.yuebao.feign.FundFeignService;
import com.yuebao.model.pojo.FundProduction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;
import java.util.List;

//冷启动

public class InitRedisData {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private FundFeignService fundFeignService;

//    @Resource
//    @DubboReference
//    private FundProductionService fundProductionService;

    public void InitRedisData(){
        System.out.println("启动时读redis到内存");
        //"fund_production:" + fundId
//        List<FundProduction> list = fundProductionService.query().list();
        List<FundProduction> list=fundFeignService.getAllFundProduction();
        System.out.println(list);
        for(FundProduction each:list){
            stringRedisTemplate.opsForValue().set("fund_production:"+each.getFundId(), JSONUtil.toJsonStr(each));
        }
        System.out.println("基金加载到Cache成功");
        //"fund_stock:"
        stringRedisTemplate.opsForValue().set("fund_stock:"+"1", "1000");
        System.out.println("库存加载成功");


    }
}
